# Some variables are followed by these abbreviations
# fct = Factor, ordered, seven levels
# cat = Factor, unordered, three levels
# bin = Factor, dummy
# num = Numeric, dummy

# Confidence in Attribution ----------------------------------------------------
df$confidence_ord <- convert_confidence(df$confidence, to = "ordered")
df$confidence_cat <- convert_confidence(df$confidence, to = "categorical")
df$confidence_bin <- convert_confidence(df$confidence, to = "dummy")

# Support for Retribution ------------------------------------------------------

df$do_nothing <- factor(df$do_nothing, levels = c(0, 1), 
                        labels = c("Do not support", "Support"))

df$do_condemn <- factor(df$do_condemn, levels = c(0, 1),
                        labels = c("Do not support", "Support"))

df$do_sanctions<- factor(df$do_sanctions, levels = c(0, 1),
                         labels = c("Do not support", "Support"))

df$do_cyberespionage <- factor(df$do_cyberespionage, levels = c(0, 1),
                               labels = c("Do not support", "Support"))

df$do_cyberduma <- factor(df$do_cyberduma, levels = c(0, 1),
                          labels = c("Do not support", "Support"))

df$do_cyberkremlin <- factor(df$do_cyberkremlin, levels = c(0, 1),
                             labels = c("Do not support", "Support"))

df$do_airstrikes <- factor(df$do_airstrikes, levels = c(0, 1),
                           labels = c("Do not support", "Support"))

df$do_rank <- dplyr::case_when(df$do_cyberkremlin == "Support" ~ 5,
                               df$do_cyberduma == "Support" ~ 4,
                               df$do_cyberespionage == "Support" ~ 3,
                               df$do_sanctions == "Support" ~ 2,
                               df$do_condemn == "Support" ~ 1,
                               df$do_nothing == "Support" ~ 0,
                               .default = NA)
                        
df$support <- factor(df$do_rank,
                     levels = c(0, 1, 2, 3, 4, 5, NA), 
                     labels = c("Nothing", 
                                "Condemn", 
                                "Sanctions", 
                                "Cyberespionage", 
                                "Cyberattack Duma", 
                                "Cyberattack Kremlin"), 
                     ordered = TRUE)

df$support_ord <- ordered(df$support)

df$support_cat <- ifelse(df$do_rank < 3, 0, ifelse(df$do_rank == 3, 1, 2)) |>
  factor(levels = c(0, 1, 2), labels = c("De-escalation", "Proportional", "Escalation")) |>
  stats::relevel(ref = "De-escalation")

df$support_bin <- ifelse(df$do_rank < 3, 0, 1) |>
  factor(levels = c(0, 1), labels = c("De-escalation", "Retaliation")) |> 
  stats::relevel(ref = "De-escalation")

# Treatment variables ----------------------------------------------------------

df$disavowal <- factor(df$disavowal, levels = c(0, 1, 2), 
                       labels = c("None", "Evidence", "Hypocrisy"))

df$endorsement <- factor(df$endorsement, levels = c(0, 1), 
                         labels = c("Bipartisan", "Partisan")) |>
  stats::relevel(ref = "Partisan")

df$interaction <- interaction(df$disavowal, df$endorsement)

treatments <- c("disavowal", "endorsement")
interactions <- "endorsement:disavowal"

# Pre-existing images ----------------------------------------------------------
df$russia <- rate_feelings(df$rate_russia, type = "all")
df$russia_imputed <- rate_feelings(df$rate_russia, type = "imputed")

countries <- c("russia")
countries_imputed <- c("russia_imputed")
